export const PHONE_BRANDS = {
    IPHONE: 'iphone',
    HUAWEI: 'huawei',
    OPPO: 'oppo',
    VIVO: 'vivo',
    XIAOMI: 'xiaomi',
    SAMSUNG: 'samsung',
    DEFAULT: 'default'
};

export const MARKET_URLS = {
    [PHONE_BRANDS.HUAWEI]: 'appmarket://details?id=com.quark.browser',
    [PHONE_BRANDS.VIVO]: 'vivomarket://details?id=com.quark.browser',
    [PHONE_BRANDS.XIAOMI]: 'mimarket://details?id=com.quark.browser',
    [PHONE_BRANDS.OPPO]: 'oppomarket://details?packagename=com.quark.browser',
    [PHONE_BRANDS.IPHONE]: 'https://www.quark.cn/',
    [PHONE_BRANDS.SAMSUNG]: 'https://www.quark.cn/',
    [PHONE_BRANDS.DEFAULT]: 'https://www.quark.cn/'
};

const judgeBrand = (sUserAgent) => {
    var isIphone = sUserAgent.match(/iphone/i) == "iphone";
    var isHuawei = sUserAgent.match(/huawei/i) == "huawei";
    var isHonor = sUserAgent.match(/honor/i) == "honor";
    var isOppo = sUserAgent.match(/oppo/i) == "oppo";
    var isOppoR15 = sUserAgent.match(/pacm00/i) == "pacm00";
    var isVivo = sUserAgent.match(/vivo/i) == "vivo";
    var isXiaomi = sUserAgent.match(/mi\s/i) == "mi ";
    var isXiaomi2s = sUserAgent.match(/mix\s/i) == "mix ";
    var isRedmi = sUserAgent.match(/redmi/i) == "redmi";
    var isSamsung = sUserAgent.match(/sm-/i) == "sm-";

    if (isIphone) {
        return PHONE_BRANDS.IPHONE;
    } else if (isHuawei || isHonor) {
        return PHONE_BRANDS.HUAWEI;
    } else if (isOppo || isOppoR15) {
        return PHONE_BRANDS.OPPO;
    } else if (isVivo) {
        return PHONE_BRANDS.VIVO;
    } else if (isXiaomi || isRedmi || isXiaomi2s) {
        return PHONE_BRANDS.XIAOMI;
    } else if (isSamsung) {
        return PHONE_BRANDS.SAMSUNG;
    } else {
        return PHONE_BRANDS.DEFAULT;
    }
}

export const getMarketUrl = () => {
    const brand = judgeBrand(navigator.userAgent.toLowerCase());
    return MARKET_URLS[brand];
}
